#!/usr/bin/env sh

# 初始化数据库，自动安装
if [[ ! -f ./application/admin/command/Install/install.lock && ${INIT_DATABASE} == true ]];then
    echo "正在执行自动安装命令..."
    set +o errexit
    while [[ 0 -eq 0 ]]
    do
        php think install -u ${DATABASE_USERNAME} -p ${DATABASE_PASSWORD}
        # check and retry
        if [[ $? -eq 0 ]]; then
            break;
        else
            echo "db service is not ready, retry in 10 seconds..."
            sleep 10s
        fi
    done
    set -o errexit
fi

touch ./application/admin/command/Install/install.lock